package com.adamfass.tractorbeam.gameupdatelogic;

import java.util.Set;

import com.adamfass.tractorbeam.Blocker;
import com.adamfass.tractorbeam.GameObjectManager;
import com.adamfass.tractorbeam.GameUpdateLogic;
import com.adamfass.tractorbeam.gameobject.DisruptorField;
import com.jme.math.Vector3f;
import com.jme.scene.Node;

public class DisruptorFieldFactory {
  private final Node rootNode;
  private final GameObjectManager gameObjectManager;
  private final Set<GameUpdateLogic> gameUpdateLogicSet;
  private final Set<Blocker> blockerSet;
  

  public DisruptorFieldFactory(Node rootNode, GameObjectManager gameObjectManager,
      Set<GameUpdateLogic> gameUpdateLogicSet, Set<Blocker> blockerSet) {
    this.rootNode = rootNode;
    this.gameObjectManager = gameObjectManager;
    this.gameUpdateLogicSet = gameUpdateLogicSet;
    this.blockerSet = blockerSet;
  }
  
  public void addDisruptorField(Vector3f position, Vector3f normal) {
    final DisruptorField field = new DisruptorField(rootNode, position, normal);
    final DisruptorFieldGameUpdateLogic logic = 
      new DisruptorFieldGameUpdateLogic(this, gameUpdateLogicSet, field, blockerSet);
    gameUpdateLogicSet.add(logic);
    blockerSet.add(field);
  }
  
  public void removeDisruptorField(DisruptorField field, 
      DisruptorFieldGameUpdateLogic logic) {
    gameUpdateLogicSet.remove(logic);
    blockerSet.remove(field);
    field.cleanUp();
  }
}
